<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 一周中的第几天 -->
    <script>
      var dayOfTheWeek = function (day, month, year) {
        const week = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
        const monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]
        //输入年份之前的年份的天数贡献
        let days = 365 * (year - 1971) + Math.floor((year - 1969) / 4)
        //输入年份中，输入月份之前的月份的天数贡献
        for (let i = 0; i < month - 1; ++i) {
          days += monthDays[i]
        }
        if ((year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0)) && month >= 3) {
          days += 1
        }
        //输入月份中的天数贡献
        days += day
        return week[(days + 3) % 7]
      }
      console.log(dayOfTheWeek(31, 8, 2019))
    </script>
  </body>
</html>
